Page({
  data: {
    name:'',
    staffid:'',
    dept:'',
    paydate:'',
    paytype:'',
    workhour:'',
    latetime:'',
    earlytime:'',
    outtime:'',
    nomarlot:'',
    yearleave:'',
    adjsutleave:'',
    deadleave:'',
    nopayleave:'',
    seakleave:'',
    merryleave:'',
    babyleave:'',
    babywatchleave:'',
    workheartleave:'',
    watchleave:'',
    doubleot:'',
    throt:'',
    shouldtime:'',
    truetime:'',
    totaltime:'',
    otapply:'',
    ctx: null,
    hasDraw:false, //默认没有画
    src:null,
     confirm :true,
     year:'',
     month:'',
     moves:true,
      isScroll: true,
  },

onLoad() {


var ctx = dd.createCanvasContext('hand');
    ctx.setStrokeStyle('blue')
       ctx.setLineWidth(3);
     // console.log(ctx);
       
       this.setData({
        ctx: ctx,
      });
  
var that=this;

  dd.getStorage({
  key: 'staffid',
  success: function(res) 
  { 
    //console.log(res.data);
  that.setData({

   staffid:res.data

  });
  dd.httpRequest({

          url:'http://ding.tida-lighting.com/api/user/worktime?staffid='+res.data,
          success: function (res) {
 
         // console.log(that.data.staffid);
          that.setData({
              dept:res.data.dept,
              zhiwu:res.data.zhiwu,
              paydate:res.data.paydate,
              paytype:res.data.paytype,
              workhour:res.data.workhour,
              latetime:res.data.minlate,
              earlytime:res.data.minealry ,
              outtime:res.data.outduty ,
              nomarlot:res.data.overtime1,
              yearleave:res.data.yearleave ,
              adjsutleave:res.data.adjustleave,
              deadleave:res.data.deadleave,
              nopayleave:res.data.nopayleave,
              seakleave:res.data.sickleave,
              merryleave:res.data.marryleave,
              babyleave:res.data.babyleave,
              babywatchleave:res.data.babykeperleave,
              workheartleave:res.data.workheartleave,
              watchleave:res.data.watchleave,
              doubleot:res.data.doubleot,
              throt:res.data.thrdot,
              shouldtime:res.data.shouldtime,
              truetime:res.data.truetime,
              totaltime:res.data.totaltime,
              otapply:res.data.otapply,
              confirm : res.data.confirm,
              year:res.data._year,
              month:res.data._month,
              
          });

          console.log(res.data);
         },
        fail: (err) => {
           //dd.alert({content: JSON.stringify(err)})
           console.log(err);
        }

     });//发起结束
  },
  fail: function(res){
    dd.alert({content: res.errorMessage});
  }
});

  dd.getStorage({
  key: 'name',
  success: function(res) {
   // console.log(res.data);
  that.setData({
   name:res.data

  });
  },
  fail: function(res){
    dd.alert({content: res.errorMessage});
  }
});



  },

   start: function(e) {
    var ctx = this.data.ctx;
    ctx.moveTo(e.touches[0].x, e.touches[0].y);
    this.setData({
      ctx: ctx,
      hasDraw : true, //要签字了
    });
   },
  move: function(e) {
    var x = e.touches[0].x;
    var y = e.touches[0].y;
    var ctx = this.data.ctx;
    ctx.setLineWidth(3);
    ctx.lineTo(x, y);
    ctx.stroke();
    ctx.setLineCap('round');
    ctx.draw(true);
    ctx.moveTo(x, y);
  },
  reSigna: function() { //重新画

var that = this;
    var ctx= that.data.ctx;
    ctx.draw(); //清空画布
    that.setData({
      hasDraw: false, //没有画
      src: null
    });



    
  },
  sig:function()
  {
       dd.navigateTo({ url:'../Test/Test' });

  },



  signoka: function () {
    var that = this;
    if(!that.data.hasDraw){
      console.log("签字是空白的 没有签字")
    }else{
      var ctx = that.data.ctx;
   
   
   ctx.toTempFilePath({
  
  success(res) {

   that.setData({
          src: res.filePath,
   });

    console.log(res);  
 
    dd.showToast({
      content:that.data.src
    });
    dd.uploadFile({
      url:'http://ding.tida-lighting.com/api/user/upload_image',
      fileType: 'image',
      fileName: 'img',
      filePath:that.data.src, 
      formData: { 'year': that.data.year,
                  'month':that.data.month,
                  'staffid':that.data.staffid,
      
      },
      

      success: function (res) {
      dd.showToast({
      content: '签核成功'
    });

        
      },fail:function(data){
        
        dd.showToast({
          content: '提交失败，请重新签名提交',
        
        })
        console.log(data);
         console.log(that.data.src);
      }
    });


  }
                   });

 
    





      

    }
  }
 
});
